package com.akk.action;

import com.akk.business.AvsPayBusiness;
import com.akk.module.avs.model.request.*;
import com.akk.utils.RestResponse;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@RequestMapping("/thmlfApi/avs/pay")
@CrossOrigin
public class AvsPayAction {

    @Autowired
    AvsPayBusiness avsPayBusiness;

    @GetMapping("/paystatus")
    @ApiOperation(value = "支付接口状态", notes = "支付接口状态", httpMethod = "GET", response = RestResponse.class)
    public RestResponse payStatus() {
        return avsPayBusiness.payStatus();
    }

    @PostMapping("/showpayaccess")
    @ApiOperation(value = "显示通道", notes = "显示可用通道", httpMethod = "POST", response = RestResponse.class)
    public RestResponse showPayAccess() {
        return avsPayBusiness.showPayAccess();
    }

    @GetMapping("/getusername")
    @ApiOperation(value = "获取用户姓名", notes = "获取用户个人姓名", httpMethod = "GET", response = RestResponse.class)
    public RestResponse getUserName(String payerId) {
        return avsPayBusiness.getUserName(payerId);
    }


    @PostMapping("/createVipPayOrder")
    @ApiOperation(value = "创建VIP缴费订单", notes = "创建VIP缴费订单", httpMethod = "POST", response = RestResponse.class)
    public RestResponse createVipPayOrder(@RequestBody CreatePayOrderRequest request) {
        return avsPayBusiness.createVipPayOrder(request);
    }

    @PostMapping("/createpayorder")
    @ApiOperation(value = "创建订单", notes = "支付创建订单", httpMethod = "POST", response = RestResponse.class)
    public RestResponse createPayOrder(@RequestBody CreatePayOrderRequest request) {
        return avsPayBusiness.createPayOrder(request);
    }

    @RequestMapping("/getpayerbind")
    @ApiOperation(value = "获取用户绑定的卡", notes = "获取用户绑定的卡", httpMethod = "GET", response = RestResponse.class)
    public RestResponse getPayerBind(@RequestParam String gateway, @RequestParam String payerId, @RequestParam String orderNum) {
        return avsPayBusiness.getPayerBind(gateway, payerId, orderNum);
    }

    @RequestMapping("/getpayerallbind")
    @ApiOperation(value = "获取用户所有绑定的卡", notes = "获取用户所有绑定的卡", httpMethod = "GET", response = RestResponse.class)
    public RestResponse getPayerAllBind(@RequestParam String payerId, @RequestParam String gateway) {
        return avsPayBusiness.getPayerAllBind(payerId, gateway);
    }

    @RequestMapping("/accessbanklist")
    @ApiOperation(value = "获取通道支持的银行", notes = "获取通道支持银行", httpMethod = "GET", response = RestResponse.class)
    public RestResponse accessBankList() {
        return avsPayBusiness.accessBankList();
    }

    @RequestMapping("/accessbanklistbyindex")
    @ApiOperation(value = "获取银行列表（索引）", notes = "获取通道支持银行（索引）", httpMethod = "GET", response = RestResponse.class)
    public RestResponse accessBankListByIndex() {
        return avsPayBusiness.accessBankListByIndex();
    }

    @PostMapping(value = "/depositcardlist")
    @ApiOperation(value = "显示结算卡绑定列表", notes = "显示结算卡绑定列表", httpMethod = "POST", response = RestResponse.class)
    public RestResponse depositCardList(@RequestParam String payerId) {
        return avsPayBusiness.depositCardList(payerId);
    }

    @PostMapping(value = "/adddepositcard")
    @ApiOperation(value = "添加结算卡", notes = "添加结算卡", httpMethod = "POST", response = RestResponse.class)
    public RestResponse addDepositCard(@Valid AddDepositCardRequest request, BindingResult result) {
        return avsPayBusiness.addDepositCard(request, result);
    }

    @GetMapping(value = "/deldepositcard")
    @ApiOperation(value = "删除结算卡", notes = "删除结算卡", httpMethod = "GET", response = RestResponse.class)
    public RestResponse delDepositCard(String cashBindId, String payerId) {
        return avsPayBusiness.delDepositCard(cashBindId, payerId);
    }

    @GetMapping(value = "/setcashcard")
    @ApiOperation(value = "设置提现卡", notes = "设置提现卡", httpMethod = "GET", response = RestResponse.class)
    public RestResponse setCashCard(@RequestParam String cashBindId, @RequestParam String payerId) {
        return avsPayBusiness.setCashCard(cashBindId, payerId);
    }

    @PostMapping(value = "/deposit")
    @ApiOperation(value = "提现到结算银行卡", notes = "提现到结算银行卡", httpMethod = "POST", response = RestResponse.class)
    public RestResponse deposit(@RequestBody @Valid DepositRequest request, BindingResult result) {
        if (result.hasErrors())
            return RestResponse.build(RestResponse.AVS_ERROR_CODE, result.getFieldError().getDefaultMessage());
        return avsPayBusiness.deposit(request);
    }

    @PostMapping(value = "/getquickaccess")
    @ApiOperation(value = "获取极速收款通道", notes = "获取极速收款通道", httpMethod = "POST", response = RestResponse.class)
    public RestResponse getQuickAccess(@RequestBody @NotBlank AvsCustomerRequest request) {
        return avsPayBusiness.getQuickAccess(request);
    }

    @PostMapping(value = "/getpayreocrd")
    @ApiOperation(value = "获取交易记录", notes = "获取交易记录", httpMethod = "POST", response = RestResponse.class)
    public RestResponse getPayeRecord(@RequestParam("payerId") String payerId, @RequestParam("appId") String appId) {
        return avsPayBusiness.getOrderRecord(payerId, appId);
    }

    @PostMapping(value = "/getpayreocrdinfo")
    @ApiOperation(value = "获取交易记录", notes = "获取交易记录详情", httpMethod = "POST", response = RestResponse.class)
    public RestResponse getPayeRecordInfo(@RequestParam("orderId") String orderId) {
        return avsPayBusiness.getOrderRecordInfo(orderId);
    }

    @GetMapping(value = "/getuservipinfo")
    @ApiOperation(value = "获取用户VIP信息", notes = "获取用户VIP信息", httpMethod = "GET", response = RestResponse.class)
    public RestResponse getUserVipInfo(String payerId) {
        return avsPayBusiness.getUserVipInfo(payerId);
    }

    @GetMapping(value = "/getpaycount")
    @ApiOperation(value = "获取用户的支付金额总和", notes = "获取用户的支付金额总和", httpMethod = "GET", response = RestResponse.class)
    public RestResponse getPayCount(String payerId) {
        return avsPayBusiness.getPayCount(payerId);
    }

    @GetMapping(value = "/getvipconfig")
    @ApiOperation(value = "获取VIP配置信息", notes = "获取VIP配置信息", httpMethod = "GET", response = RestResponse.class)
    public RestResponse getVipConfig() {
        return avsPayBusiness.getVipConfig();
    }

    @PostMapping(value = "/getvipreward")
    @ApiOperation(value = "VIP奖励金提现", notes = "VIP奖励金提现", httpMethod = "POST", response = RestResponse.class)
    public RestResponse getVipReward(AvsPayVipRewardRequest request, HttpServletRequest servletRequest) {
        return RestResponse.build(RestResponse.AVS_ERROR_CODE, "维护中，敬请期待");
//        return avsPayBusiness.getVipReward(request,servletRequest);
    }

    @GetMapping(value = "/transferquery")
    @ApiOperation(value = "查询订单是否提现成功", notes = "查询订单是否提现成功", httpMethod = "GET", response = RestResponse.class)
    public RestResponse transferQuery(String orderNum) {
        return avsPayBusiness.transferQuery(orderNum);
    }

    @GetMapping(value = "/depositprogress")
    public RestResponse depositProgress(String orderNum) {
        return avsPayBusiness.depositProgress(orderNum);
    }

    @GetMapping(value = "/deleteorder")
    @ApiOperation(value = "删除订单", notes = "只能删除未付款订单", httpMethod = "GET", response = RestResponse.class)
    public RestResponse deleteOrder(String orderId, String payerId) {
        return avsPayBusiness.deleteOrder(orderId, payerId);
    }

}
